/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package objective;

/**
 *
 * @author daz
 */
public class KelementInSet implements IObjective {

    private int k;
    private int[] element;
    private int[] set;
    private int violateDegrees;

    public KelementInSet(int k, int[] element, int[] set) {
        this.k = k;
        this.element = element;
        this.set = set;
        this.violateDegrees = calculateViolation(k, element, set);
    }

    private int calculateViolation(int k, int[] element, int[] set) {
        int result = 0;
        for (int i = 0; i < element.length; i++) {
            for (int j = 0; j < set.length; j++) {
                if (element[i] == set[j]) {
                    result++;
                }
            }
        }
        if (result >= k) {
            return 0;
        }
        return k - result;
    }

    @Override
    public int getAssignDelta(int index, int newValue) {
        set[index] = newValue;
        return calculateViolation(k, element, set) - violateDegrees;
    }

    @Override
    public int getViolateDegrees() {
        return this.violateDegrees;
    }
}
